import React from 'react';

export const useGetExtraInfo = (fields: any, id: string, form: any) => {
  const [extra, setExtra] = React.useState<any>({});

  React.useEffect(() => {
    if (fields) {
      const Extra = fields.get(id);
      if (Extra) {
        const _extra = new Extra();
        console.log(`${id}=====`, _extra);
        const _info = _extra.__type__.__fields_value__;

        // 将map转化为对象
        const _extraInfo: any = {};
        for (const [k, v] of _info) {
          _extraInfo[k] = v;
        }

        if (_extraInfo.defaultValue) {
          form.setFieldsValue({ [id]: _extraInfo.defaultValue });
        }

        setExtra({ ..._extraInfo });
      }
    }
  }, [fields, id]);

  return extra;
};
